package pl.plesken.xml;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class LibrariesXML {
	
	StringBuffer libxml = new StringBuffer();
	
		
	public void saveLibrary() {
        try {
        	HostsXML host = new HostsXML();	
		
        	FileOutputStream lib = new FileOutputStream("libraries.xml");
        	BufferedWriter xml = new BufferedWriter(new OutputStreamWriter(lib));
       
        	host.readHostValues();
        
        	libxml.setLength(0);
        	libxml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<libraries>\n");
       
        	for (int i = 0; i < host.getRow().size(); i++) {
                //String[] tab = host.getRow().get(i).split("<BREAK>");
                if (host.getRow().get(i).getStat().toString().equals("enable")) {
                        libxml.append(" <library>\n");
                        libxml.append("   <path>" + host.getRow().get(i).getSrc().toString() + File.separator + "</path>\n");
                        libxml.append("   <nmtpath>" + host.getRow().get(i).getNmt().toString() + "</nmtpath>\n");
               
                        if (!host.getRow().get(i).getExcl().toString().equals("")) {
                                libxml.append("   <exclude name=\"" + host.getRow().get(i).getExcl().toString() + "\"/>\n");
                        }
               
                        libxml.append("   <description>" + host.getRow().get(i).getName().toString() + "</description>\n");
                        libxml.append(" </library>\n");  
                }
        	}

        	libxml.append("</libraries>");
       
        	xml.write(libxml.toString());
       
        	xml.close();	
		
        } catch(IOException e) {
        }
	}

}
